package org.example.fastJsonEnumSerializer;

import com.alibaba.fastjson2.JSON;
/**
 * 用来将带有枚举的实体类进行json的序列化和反序列化
 * 使用的是fastjson2
 * */
public class FastJsonSerializerMain {
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        // 序列化
        OrderStatus status = OrderStatus.CANCELLED;
        String json = JSON.toJSONString(status);
        System.out.println(json); // 输出:

        // 反序列化
        OrderStatus deserialized = JSON.parseObject(json, OrderStatus.class);
        System.out.println(deserialized == OrderStatus.CANCELLED); // 输出: true

        // 复杂对象
        Order order = new Order("123", OrderStatus.SHIPPED);
        String orderJson = JSON.toJSONString(order);
        Order parsedOrder = JSON.parseObject(orderJson, Order.class);


    }
    static class Order {
        private String id;
        private OrderStatus status;

        public Order(String id, OrderStatus status) {
            this.id = id;
            this.status = status;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public OrderStatus getStatus() {
            return status;
        }

        public void setStatus(OrderStatus status) {
            this.status = status;
        }
// 构造器、getter和setter
    }
}
